package com.zjj.lbw.ai;

import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.zhipu.ZhipuAiChatModel;
import dev.langchain4j.service.AiServices;
import dev.langchain4j.service.SystemMessage;
import dev.langchain4j.service.UserMessage;
import dev.langchain4j.service.V;

public class ArticleHelper {
    interface Writer {
        @SystemMessage("帮我写一篇作文，字数不超过{{count}}字")
        String write(@UserMessage String title, @V("count") Integer count);

        // 进一步封装
        static Writer create() {
            ChatLanguageModel model = ZhipuAiChatModel.builder()
                    .apiKey("9a6dfc4258104e28ad0c72db2ddda3e4.f6VL6AWRQxORuJpi")
                    .build();
            return AiServices.builder(Writer.class)
                    .chatLanguageModel(model)
                    .build();
        }
    }

    public static void main(String[] args) {
        ChatLanguageModel model = ZhipuAiChatModel.builder()
                .apiKey("9a6dfc4258104e28ad0c72db2ddda3e4.f6VL6AWRQxORuJpi")
                .build();

//        String result = model.generate("帮我写一篇作文，标题为我最爱的人");
//        System.out.println(result);

        Writer writer = AiServices.create(Writer.class, model);
        String result2 = writer.write("我最爱的人", 100);
        System.out.println(result2);
    }
}
